#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int mod=1e9+7;
char a[55];
int n,cnt[11];
int fac[55],inv[55],ans;
inline int ksm(int a,int k){
	int res=1;
	for(;k;k>>=1,a=1ll*a*a%mod)
		if(k&1)res=1ll*res*a%mod;
	return res;
}
inline int C(int n,int m){
	if(n<0||m<0)return 0;
	if(n<m)return 0;
	return 1ll*fac[n]*inv[n-m]%mod*inv[m]%mod;
}
int pd[11];
int f[11],g[11];
void dfs(int x,int sum){
	if(x==10){
		int res=1ll*(sum-cnt[0])*fac[sum-1]%mod;
		int val=0;
		for(int i=0;i<=9;i++){
			if(cnt[i]>=cnt[val])val=i;
			res=1ll*res*inv[cnt[i]]%mod;
		}
		ans=(ans+1ll*res*val%mod)%mod;
		res=0;
		int cnt1=0;
		for(int i=9;~i;i--){
			cnt1+=pd[i];
			res=1ll*res*C(cnt1,cnt[i])%mod;
			cnt1-=cnt[i];
		}g[10]=1;
		ans=(ans+1ll*res*val%mod)%mod;
		return;
	}
	for(int i=0;i<=n-sum;i++)cnt[x]=i,dfs(x+1,sum+i),cnt[x]=0;
}
void dfs1(int x,int sum){
	if(x==10){
		int res=1ll*(sum-cnt[0])*fac[sum-1]%mod;
		int val=0;
		for(int i=0;i<=9;i++){
			if(cnt[i]>=cnt[val])val=i;
			res=1ll*res*inv[cnt[i]]%mod;
		}
		ans=(ans+1ll*res*val%mod)%mod;
		return;
	}
	for(int i=0;i<n-sum;i++)cnt[x]=i,dfs1(x+1,sum+i),cnt[x]=0;
}
int main(){
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	freopen("give.in","r",stdin);
	freopen("give.out","w",stdout);
	int T=read();
	fac[0]=1;inv[0]=1;
	for(int i=1;i<=50;i++)fac[i]=1ll*fac[i-1]*i%mod,inv[i]=ksm(fac[i],mod-2);
	while(T--){
		ans=0;
		scanf("%s",a+1);
		n=strlen(a+1);
		for(int i=0;i<=9;i++)pd[i]=0;
		for(int i=2;i<=n;i++)pd[a[i]-48]++;
		dfs1(0,0);int res=1ll*ans*(a[1]-49)%mod;
		for(int i=0;i<=9;i++)pd[i]=0;
		pd[9]=n-1;
		ans=0;dfs(0,0);
		res=(ans+res)%mod;
		printf("%lld\n",res);
	}
	return 0;
}

